package com.ktwlsoft.archivemanage.domain.business.repositoryService;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ktwlsoft.archivemanage.domain.dao.entity.Account;
import com.ktwlsoft.archivemanage.domain.dao.repository.IAccountMapper;
import com.ktwlsoft.archivemanage.payload.role.EditRoleRequest;
import com.ktwlsoft.archivemanage.payload.security.AccountResponse;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * account--账号业务层接口实现类
 *
 * @author zhuhe on 2019-10-24 14:19:38
 * @version 1.0
 */
@Service
public class AccountRepositoryService {
    @Getter
    private final IAccountMapper accountMapper;

    public AccountRepositoryService(IAccountMapper accountMapper) {
        this.accountMapper = accountMapper;
    }

    /**
     * 查询分页 on 2019-10-24 14:19:38
     *
     * @param pn       第几页
     * @param pageSize 每页多少条
     * @param account  account
     * @return PageInfo<Account>
     */
    public PageInfo<Account> findPage(int pn, int pageSize, Account account) {
        PageHelper.startPage(pn, pageSize);
        List<Account> list = accountMapper.findList(account);
        return new PageInfo<Account>(list);
    }

    /**
     * 查询集合 on 2019-10-24 14:19:38
     *
     * @param account account
     * @return List<Account>
     */
    public List<Account> findList(Account account) {
        return accountMapper.findList(account);
    }

    /**
     * 根据ID查询信息 on 2019-10-24 14:19:38
     *
     * @param id 主键
     * @return Account
     */
    public Account getById(Long id) {
        return accountMapper.getById(id);
    }

    /**
     * 根据部门ID查询信息 on 2019-10-24 14:19:38
     *
     * @param departmentId 部门ID
     * @return Account
     */
    public List<Account> getByDepartmentId(Long departmentId) {
        return accountMapper.getByDepartmentId(departmentId);
    }

    /**
     * 根据用户账号查询信息 on 2019-10-24 14:19:38
     *
     * @param userName userName
     * @return Account
     */
    public Account getByUserName(String userName) {
        return accountMapper.getByUserName(userName);
    }

    public AccountResponse findByUserName(String userName) {
        return accountMapper.findByUserName(userName);
    }

    /**
     * 根据电话号码查询数据 on 2019/10/31 12:01
     *
     * @param teleNum teleNum
     * @return Account
     */
    public List<Account> getByTeleNum(String teleNum) {
        return accountMapper.getByTeleNum(teleNum);
    }

    /**
     * 新增 on 2019-10-24 14:19:38
     *
     * @param account account
     * @return int
     */
    public int insert(Account account) {
        return accountMapper.insert(account);
    }

    /**
     * 修改 on 2019-10-24 14:19:38
     *
     * @param account account
     * @return int
     */
    public int update(Account account) {
        return accountMapper.update(account);
    }

    /**
     * 批量更新 on 2019/6/12 9:35
     *
     * @param jsonObject jsonObject
     * @return int
     */
    public int manyUpdate(JSONObject jsonObject) {
        return accountMapper.manyUpdate(jsonObject);
    }

    /**
     * 根据id集合批量删除信息 on 2019-10-24 14:19:38
     *
     * @param accountArr 主键编号集合
     * @return int
     */
    public int deleteByIds(List<Long> accountArr) {
        return accountMapper.deleteByIds(accountArr);
    }

    /**
     * 根据id删除信息 on 2019-10-24 14:19:38
     *
     * @param id id
     * @return int
     */
    public int deleteById(Long id) {
        return accountMapper.deleteById(id);
    }

    /**
     * 检查唯一 on 2019-10-24 14:19:38
     *
     * @param account account
     * @return int
     */
    public List<Account> checkUnique(Account account) {
        return accountMapper.checkUnique(account);
    }

    public int updateRoleInfo(EditRoleRequest request) {
        return accountMapper.updateRoleInfo(request);
    }

    /**
     * 查询列表排除立档单位 on 2019-10-24 14:19:38
     *
     * @param pn       第几页
     * @param pageSize 每页多少条
     * @param account  account
     * @return PageInfo<Account>
     */
    public PageInfo<Account> findPageNotUnit(int pn, int pageSize, Account account) {
        PageHelper.startPage(pn, pageSize);
        List<Account> list = accountMapper.findListNotUnit(account);
        return new PageInfo<Account>(list);
    }
}
